package Thread;

import java.util.concurrent.TimeUnit;

class MyData{
    public volatile int number = 0;
    public void change(){
        number = 60;
    }
}

public class VolatileTest {
    public static void main(String[] args) {
        MyData myData = new MyData();
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "number is :"+ myData.number);
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            myData.change();
            System.out.println(Thread.currentThread().getName() + "has changed" + myData.number);
        },"A").start();
        while(myData.number == 0){

        }
        System.out.println(Thread.currentThread().getName() + "number is:" + myData.number);
    }
}
